home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 05 - 1989 / 05.10 Oct 89 / CursorWrap INIT Code / MTCursorWrap.p < prev    next >
Encoding:
Text File  |  1988-10-02  |  3.4 KB  |  168 lines  |  [TEXT/MPS ]

  1. Unit CursorWrap;
  2.  
  3. Interface
  4.  
  5. Uses
  6.     {$LOAD MAC.Dump}
  7.     MemTypes,QuickDraw,OSIntf,Toolintf,PackIntf,Script;
  8.  
  9. Procedure SetUpVBL;
  10. Procedure Wrap;
  11.  
  12. Implementation
  13.  
  14. Procedure SetUpVBL;
  15.  
  16. var
  17.     theVBL            : VBLTask;
  18.     myQElem            : QElemPtr;
  19.     myErr                : OSErr;
  20.     SaveZone        :    THz;
  21.     SizeNeeded    :    Longint;
  22.     PatchPtr        : Ptr;
  23.     theCode            : Handle;
  24.     thePtr            : ^LongInt;
  25.     dummyErr        :    OSErr;
  26.     
  27. Begin
  28.     { * Get handle to our code *}
  29.     theCode:=Get1Resource('INIT',1);
  30.     
  31.     { * Use the system's Heap * }
  32.     SaveZone:=GetZone;
  33.     SetZone(SystemZone);
  34.     
  35.     { * Get size of our patch code and our QElem ptr * }
  36.     SizeNeeded:=SizeResource(theCode)-(LongInt(@SetUpVBL)-LongInt(theCode^))+sizeof(QElem);
  37.     ResrvMem(SizeNeeded);
  38.     If MemError<>NoErr then
  39.         begin
  40.             { * If not enouph room in system heap then get out * }
  41.             SysBeep(1);
  42.             SetZone(SaveZone);
  43.             exit(SetUpVBL);
  44.         end;
  45.     
  46.     { * Get new ptr for our code * }
  47.     PatchPtr:=NewPtr(SizeNeeded+4);
  48.     
  49.     { * blockmove our code in * }
  50.     BlockMove(@Wrap,Pointer(Ord(PatchPtr)+4),SizeNeeded);
  51.     
  52.     { * get new ptr for our VBL task * }
  53.     myQElem:=QElemPtr(NewPtr(sizeof(QElem)));
  54.     
  55.     { * restore zone * }
  56.     SetZone(SaveZone);
  57.     
  58.     { * put our vbl task ptr's address into the ptr where our patch code will be * }
  59.     thePtr:=Pointer(PatchPtr);
  60.     thePtr^:=LongInt(myQElem);
  61.     
  62.     { * set up VBL and install * }
  63.     with theVBL do
  64.         begin
  65.             qType:=Ord(vType);
  66.             vblAddr:=Pointer(Ord(PatchPtr)+4);
  67.             vblCount:=6;
  68.             vblPhase:=0;
  69.         end;
  70.     myQElem^.vblQElem:=theVBL;
  71.     
  72.     dummyErr:=VInstall(myQElem);
  73. End;
  74. {-----------------------------------------------------------------------------}
  75. Procedure Wrap;
  76.  
  77. {
  78.     **
  79.     
  80.     This code allows the cursor to seemly wrap around the screen when the
  81.     <Option> key is held down.
  82.     
  83.     **
  84. }
  85.  
  86. const
  87.     CurrentA5    =    $904;
  88.  
  89. var
  90.     myQElem                    : QElemPtr;
  91.     thePtr                    : ^LongInt;
  92.     CursorCoordPtr    : ^Point;
  93.     ChangedPtr            : ^Byte;
  94.     changed                    : Boolean;
  95.     theMap                    : KeyMap;
  96.     currGDevice            :    GDHandle;
  97.     myRectPtr                :    ^Rect;
  98.     myPtr,myPtr2        :    ^longint;
  99.     mouseRect                :    Rect;
  100.     
  101. Begin
  102.     { * Get the keymap and check if option down; if is not then do not allow wrap * }
  103.     GetKeys(theMap);
  104.     If theMap[58] then
  105.         Begin
  106.             { * set up ptr to low memory global of cursor location * }
  107.             CursorCoordPtr:=Pointer($828);
  108.             changed:=false;
  109.             
  110.             { * get rectangle of screen * }
  111.             currGDevice:=GetGDevice;
  112.             If currGDevice<>Nil
  113.                 then
  114.                     mouseRect:=currGDevice^^.gdRect
  115.                 else
  116.                     begin
  117.                         myPtr:=pointer(CurrentA5);
  118.                         myPtr2:=pointer(myPtr^);
  119.                         myRectPtr:=Pointer(myPtr2^-116);
  120.                         
  121.                         mouseRect:=myRectPtr^;
  122.                     end;
  123.             InsetRect(mouseRect,1,1);
  124.             
  125.             { * check cursor location and change it if wrapping * }
  126.             With CursorCoordPtr^,mouseRect do
  127.                 Begin
  128.                     if v<=top then
  129.                         Begin
  130.                             v:=bottom-1;
  131.                             changed:=true;
  132.                         End
  133.                     else if v>=bottom then
  134.                         Begin
  135.                             v:=top+1;
  136.                             changed:=true;
  137.                         End;
  138.                         
  139.                     if h<=left then
  140.                         Begin
  141.                             h:=right-1;
  142.                             changed:=true;
  143.                         End
  144.                     else if h>=right then
  145.                         Begin
  146.                             h:=left+1;
  147.                             changed:=true;
  148.                         End;
  149.                 End;
  150.             
  151.             { * if we changed the cursor location then set the low memory global cursorNew * }
  152.             If changed then
  153.                 Begin
  154.                     changedPtr:=Pointer($8CE);
  155.                     { * this tells the cursor drawing routines that the cursor is moved * }
  156.                     changedPtr^:=$FF;
  157.                 End;
  158.         End;
  159.     
  160.     { * get ptr to VBL taks from where we originally put it * }
  161.     thePtr:=Pointer(Ord(@Wrap)-4);
  162.     
  163.     { * reset the vblcount so that we are executed again * }
  164.     myQElem:=QElemPtr(thePtr^);
  165.     myQElem^.vblQElem.vblCount:=6;
  166. End;
  167.  
  168. End.